<?php
    header('Content-Type: text/html; charset=utf8');
    include '../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $oids = $_REQUEST['oids'];
    
        
    $listado = "select h.usu_oid as asignado,dntiponece.oidencar as ldetec,h.hisoid as hisoid,h.dnsolicitud,hisfecmod,hisestado,
                       (rtrim(usuario.usu_nombres) + '  ' + usuario.usu_apellidos)as nombres,hisadjuntos,cast(hisobs as text)as obsh,
                       case when dnobshisto.observacion is null then '' else cast(dnobshisto.observacion as text) end as obs,
                       ltrim(rtrim(case when obse.observacion is null then '' else obse.observacion end)) as obse
                from dnhistorial as h left outer join usuario on h.usu_oid=usuario.usu_oid
                                 left outer join dnobshisto on h.hisoid = dnobshisto.hisoid
                                 left outer join dnsolicitud on h.dnsolicitud = dnsolicitud.dnsoid
                                 left outer join dntiponece on dnsolicitud.tipoid = dntiponece.tipoid
                     outer apply(select count(*)as observacion
                                 from dnobshisto 
                                 where hisoid = h.hisoid)as obse
                where dnsolicitud=".$oids;
     $res = $con->query($listado);
      
    while
        ($re = mssql_fetch_array($res)){
        $lista[] = $re; 
    }
    
    $con->cerrarConexion();
    print_r(json_encode($lista))
?>